﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using Common;

namespace Habito.Admini
{
	public partial class SolutionClass : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

			if (string.IsNullOrEmpty(Ticket.UserName) || Session["username"] == null)
			{
				Response.Redirect("Login.aspx");
			}
		}
		protected override void OnInit(EventArgs e)
		{
			if (Request.QueryString["SaveSolutionClass"] == "1")
			{
				int id = int.Parse(Request.QueryString["id"].Replace("\'", ""));
				string className = Request.QueryString["className"];
				Ajax.Model.SolutionClass cla = new Ajax.Model.SolutionClass();
				cla.ID = id;
				cla.ClassName = className;
				Ajax.BLL.SolutionClass cll = new Ajax.BLL.SolutionClass();

				if (id == 0)
				{
					cll.Add(cla);
					Response.Write(JsonConvert.SerializeObject(cll.GetModel(cll.GetMaxId())));
					Response.End();
				}
				else
				{
					cla.ID = id;
					cll.Update(cla);
					Response.Write(JsonConvert.SerializeObject(cla));
					Response.End();
				}
			}
			else if (Request.QueryString["GetAllSolutionClass"] == "1")
			{
				Ajax.BLL.SolutionClass products = new Ajax.BLL.SolutionClass();
				List<Ajax.Model.SolutionClass> list = new List<Ajax.Model.SolutionClass>();
				list = products.GetModelList("");
				Response.Write(JsonConvert.SerializeObject(list));
				Response.End();
			}
			else if (Request.QueryString["DeleteSolutionClass"] == "1")
			{
				int id = int.Parse(Request.QueryString["id"]);
				Ajax.BLL.SolutionClass cla = new Ajax.BLL.SolutionClass();
				Response.Write(JsonConvert.SerializeObject(cla.Delete(id)));
				Response.End();
			}
			base.OnInit(e);
		}
	}
}